from .models import *
from utils.wrapper import *



# 校验用户提交评论表单数据
def check_response_input(request):

    user_name = post(request,"user_name")
    response = post(request,"response")

    flag = True

    if len(user_name)>10:
        add_message(request, "error_name", "用户名长度应小于10~")
        flag = False

    if len(response) > 120:
        add_message(request, "error_msg", "评论长度应小于120~")
        flag = False

    return flag

# 组装数据为json格式
def make_json(more_responses):
    re_list = list()
    for response in more_responses:
        re_dic = dict()
        re_dic["user_name"] = response.user_name
        re_dic["response"] = response.response
        # 处理时间格式
        re_time = deal_time(str(response.update_time))
        re_dic["re_time"] = re_time
        re_list.append(re_dic)
    return re_list